package Test;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class TestDemo13 {
    public static void main(String[] args) throws InterruptedException {
        AtomicInteger atomicInteger = new AtomicInteger();
        new Thread(new Runnable() {
            @Override
            public void run() {
                if(atomicInteger.get() == 0) {
                    System.out.println("A线程进来了");
                    atomicInteger.incrementAndGet();
                }
            }
        },"A").start();

        TimeUnit.SECONDS.sleep(1);
        new Thread(new Runnable() {
            @Override
            public void run() {
                if(atomicInteger.get() == 1) {
                    System.out.println("C线程进来了");
                    atomicInteger.incrementAndGet();
                }
            }
        },"C").start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                if(atomicInteger.get() == 2) {
                    System.out.println("B线程进来了");
                    atomicInteger.incrementAndGet();
                }
            }
        },"B").start();
    }
}
